package com.ft.turorial.spring.boot.service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import com.ft.turorial.spring.boot.domain.User;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
    private JdbcTemplate jdbcTemplate;
	@Override
	public List<User> getList() {
		String sql = "SELECT ID,NAME FROM user";
        return (List<User>) jdbcTemplate.query(sql, new RowMapper<User>(){
            @Override
            public User mapRow(ResultSet rs, int rowNum) throws SQLException {
            	User stu = new User();
                stu.setId(rs.getInt("ID"));
                stu.setName(rs.getString("NAME"));
                return stu;
            }
        });
	}

}
